package org.hzero.order.app.service.impl;

import org.hzero.order.app.service.HeaderService;
import org.hzero.order.domain.entity.Header;
import org.hzero.order.domain.repository.HeaderRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author xiuiqng.Yang-Estelle-양수청
 * @date 2019/8/7 19:40
 */
@Service
public class HeaderServiceImpl implements HeaderService {

    @Autowired
    private HeaderRepository headerRepository;

    @Transactional(rollbackFor = Exception.class)
    @Override
    public Header insertHeader(Header header) {
        headerRepository.insert(header);
        return header;
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public Header updateHeader(Header header) {
        Header header1 = headerRepository.selectByPrimaryKey(header.getSoHeaderId());
        if (header1!=null){
            headerRepository.updateByPrimaryKeySelective(header);
        }
        return header;
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public Header deleteHeader(Header header) {
        Header header1 = headerRepository.selectByPrimaryKey(header.getSoHeaderId());
        if (header1!=null){
            headerRepository.delete(header);
        }
        return header;
    }
}
